package com.example.goodtrash.util;


import android.widget.Toast;

import com.example.goodtrash.model.HotSearch;
import com.example.goodtrash.model.NewsResult;
import com.example.goodtrash.model.Result;
import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Utility {
    public static Result handleTrashResponse(String response){
        JSONObject jsonObject= null;
        try {
            jsonObject = new JSONObject(response);
            JSONObject jsonObject1=jsonObject.getJSONObject("result");
            String TrashContent=jsonObject1.toString();
            return new Gson().fromJson(TrashContent,Result.class);
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }


    }

    public static HotSearch handleNewsResponse(String response){
        JSONObject jsonObject= null;
        try {
            jsonObject = new JSONObject(response);
            String NewsContent=jsonObject.toString();
            return new Gson().fromJson(NewsContent,HotSearch.class);
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }

    }
    public static Result handleImageResponse(String response){
        JSONObject jsonObject= null,jsonObject1=null;
        try {
            jsonObject = new JSONObject(response);
            jsonObject1=jsonObject.getJSONObject("result");
            String TrashContent=jsonObject1.toString();
            return new Gson().fromJson(TrashContent,Result.class);
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static NewsResult handleTrashNewsResponse(String response){
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(response);
            String NewsContent=jsonObject.toString();
            return  new Gson().fromJson(NewsContent,NewsResult.class);
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }

    }
}
